/**
 * Created by sun on 2016/8/4.
 */
define(function (require) {
    var app = require('/../js/app');
    require('ui-table');

    var toastr =require('toastr');
    app.useModule("ui.table");


    var datepicker = require('datepicker');
    app.controller('itemCtrl', ['$scope','$http','$filter' ,function ($scope, $http,$filter) {
        $scope.orderParams = {
            url: "/admin/picture/itemPicture"
        };
        datepicker($scope);

        $scope.ctrlScope=$scope;

        $scope.ctrlScope.picture={};

        //创建
        $scope.addOrderModal=function(){
            $scope.orderModal = !$scope.orderModal ;
        };
        $scope.openMaxPic= function (url) {
            $scope.MaxPicModal = !$scope.MaxPicModal;
            $scope.url=url
        };
        //全局查询
        $scope.search = function() {
            //表格查询参数设置
            $scope.orderParams.ajaxParam=$scope.ctrlScope.itemsearch;
            //表格刷新
            $scope.orderParams.reload();
        };

        //全局查询重置
        $scope.reset=function(){
            $scope.ctrlScope.itemsearch={};
            $scope.orderParams.ajaxParam={};
            $scope.orderParams.reload();
        };

        //打开修改弹出框
        $scope.modifyModel=function(id,itemType){
            $scope.detailModal=! $scope.detailModal;
            $scope.ctrlScope.itemPictureType=itemType;
            $scope.ctrlScope.picture.id=id;
        };

        //修改
        $scope.modify=function(){
            var param=$scope.ctrlScope.picture;
            console.info(param);
            $http({
                method: 'POST',
                url: "/admin/picture/modifyItemPictureTypeById",
                data:param,
            }).success(function(data) {
                if(data.result=="fail"){
                    toastr.error(data.messageText);
                }else{
                    toastr.success("修改成功");
                    $scope.detailModal=! $scope.detailModal;
                    $scope.orderParams.reload();
                }
            }).error(function(data) {
            });
        };
    }]);


});